<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>仿制新浪微博博客首页</title>
    <link rel="stylesheet" href="./css/Element-ui.css" />
    <link rel="stylesheet" href="./css/TDesign.min.css" />
    <!-- 引入图标库 -->
    <link
      href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
      rel="stylesheet"
    />
  </head>
  <style>
    body {
      background-color: #f1f2f5;
      margin: 0px;
      font-family: Microsoft YaHei;
    }
    .button {
      color: black;
      font-size: 15px;
      padding: 3px;
    }

    .button:hover {
      background-color: #f6e6d4;
      color: #ff8200;
      padding-left: 8px;
      padding-right: 8px;
      border-radius: 30px;
    }

    .fullhot {
      font-size: 13px;
    }

    .fullhot:hover {
      color: #ff8200;
    }
    .fade-enter-active,
    .fade-leave-active {
      transition: transform 0.5s;
    }
    .fade-enter,
    .fade-leave-to {
      transform: translateY(-100%);
    }
    #icon {
      font-size: 30px;
    }
    .el-menu-item:hover {
      outline: 0;
      background-color: #f1f2f5;
    }
    .el-menu-item.is-active {
      background-color: white;
    }
    .el-menu-item,
    .el-submenu__title {
      height: 40px;
    }
    #blogsend > i {
      padding: 4px;
    }
    #blogsend:hover {
      color: #ff8200;
    }
    #blogsend:hover > i {
      color: #ff8200;
      background-color: #ffcc96;
      padding: 4px;
      border-radius: 100px;
    }
    .el-textarea__inner:hover {
      display: block;
      resize: vertical;
      padding: 5px 15px;
      line-height: 1.5;
      box-sizing: border-box;
      width: 100%;
      font-size: inherit;
      color: #606266;
      background-color: #fff;
      background-image: none;
      border: 1px solid #ff8200;
      border-radius: 4px;
      -webkit-transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
      transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
    }
  </style>
  <body>
    <div id="app">
      <el-container>
        <el-header style="padding: 0px; position: relative">
          <transition name="fade">
            <el-row
              id="hideNavbar"
              type="flex"
              justify="center"
              align="middle"
              style="
                background-color: white;
                height: 60px;
                width: 100%;
                position: absolute;
              "
            >
              <el-col span="2">
                <img src="img/weibo.jpg" style="width: 100px" />
              </el-col>
              <el-col span="3">
                <div
                  style="
                    background-color: #f1f2f5;
                    border-radius: 20px;
                    color: #919191;
                    font-size: 15px;
                    padding: 5px;
                    width: 150px;
                  "
                >
                  <i class="el-icon-search" style="color: black"></i>
                  搜索微博
                </div>
              </el-col>
              <el-col span="11">
                <el-menu
                  :default-active="activeIndex"
                  class="el-menu-demo"
                  mode="horizontal"
                  @select="handleSelect"
                  text-color="black"
                  active-text-color="#ff8200"
                  style="display: flex; justify-content: space-between"
                >
                  <el-menu-item index="1"
                    ><i class="el-icon-house" id="icon"></i
                  ></el-menu-item>
                  <el-menu-item index="2"
                    ><i class="fa fa-tv" id="icon"></i
                  ></el-menu-item>
                  <el-menu-item index="3"
                    ><i class="fa fa-fire" id="icon"></i
                  ></el-menu-item>
                  <el-menu-item index="4"
                    ><i class="el-icon-message" id="icon"></i
                  ></el-menu-item>
                  <el-menu-item index="5"
                    ><i class="fa fa-user-o" id="icon"></i
                  ></el-menu-item>
                </el-menu>
              </el-col>
              <el-col span="6">
                <el-row :gutter="20">
                  <el-col span="6">
                    <div
                      style="
                        background-color: #ff8200;
                        color: white;
                        padding: 5px;
                        border-radius: 20px;
                        text-align: center;
                        font-size: 13px;
                        width: 70px;
                      "
                    >
                      登录
                    </div>
                  </el-col>
                  <el-col span="6">
                    <div
                      style="
                        background-color: white;
                        color: black;
                        padding: 5px;
                        border-radius: 20px;
                        text-align: center;
                        font-size: 13px;
                        width: 70px;
                      "
                    >
                      注册
                    </div>
                  </el-col>
                  <el-col span="6">
                    <i
                      class="el-icon-edit-outline"
                      style="
                        background-color: #ff8200;
                        color: white;
                        padding: 7px;
                        font-size: 20px;
                        border-radius: 20px;
                      "
                      @click="writeBlog"
                    ></i>
                  </el-col>
                  <el-col span="6">
                    <div
                      style="
                        background-color: #f1f2f5;
                        color: black;
                        padding: 5px;
                        border-radius: 20px;
                        text-align: center;
                        font-size: 13px;
                        width: 70px;
                      "
                    >
                      无障碍
                    </div>
                  </el-col>
                </el-row>
              </el-col>
            </el-row>
          </transition>
        </el-header>

        <el-main style="padding: 0px; margin-top: 10px; height: 100vh">
          <el-row style="margin: 0 200px 0 200px" gutter="10">
            <el-col span="4" style="height: 100%; position: sticky; top: 0px">
              <el-card style="height: 100vh">
                <el-menu
                  default-active="1"
                  class="el-menu-vertical-demo"
                  @open="handleOpen"
                  @close="handleClose"
                  active-text-color="#ff8200"
                  style="border-right: solid 0px"
                >
                  <el-menu-item index="1" @click="refrashBlog">
                    <i class="fa fa-fire"></i>
                    <span slot="title">热门微博</span>
                  </el-menu-item>

                  <el-menu-item index="2">
                    <i class="fa fa-clock-o"></i>
                    <span slot="title">热门榜单</span>
                  </el-menu-item>
                  <el-menu-item index="3">
                    <i class="fa fa-search"></i>
                    <span slot="title">热搜榜</span>
                  </el-menu-item>
                  <el-menu-item index="4">
                    <i class="fa fa-star-o"></i>
                    <span slot="title">文娱榜</span>
                  </el-menu-item>
                  <el-menu-item index="5">
                    <i class="fa fa-newspaper-o"></i>
                    <span slot="title">要问榜</span>
                  </el-menu-item>
                </el-menu>
              </el-card>
            </el-col>
            <el-col span="14">
              <!-- 博客输入框部分 -->
              <el-card style="margin-bottom: 7px">
                <el-input
                  type="textarea"
                  :rows="2"
                  placeholder="有什么新鲜事儿想分享给大家？"
                  v-model="textarea"
                >
                </el-input>
                <el-row style="color: #838383; margin-top: 10px">
                  <el-col span="18">
                    <el-row style="font-size: 14px">
                      <el-col span="4">
                        <div id="blogsend">
                          <i class="fa fa-smile-o"></i>
                          表情
                        </div>
                      </el-col>
                      <el-col span="4">
                        <div id="blogsend">
                          <i class="fa fa-image"></i>
                          图片
                        </div></el-col
                      >
                      <el-col span="4">
                        <div id="blogsend">
                          <i class="fa fa-file-video-o"></i>
                          视频
                        </div></el-col
                      >
                      <el-col span="4">
                        <div id="blogsend">
                          <i class="fa fa-hashtag"></i>
                          话题
                        </div></el-col
                      >
                      <el-col span="6">
                        <div id="blogsend">
                          <i class="fa fa-flash"></i>
                          头条文章
                        </div></el-col
                      >
                      <el-col span="2">
                        <div id="blogsend">
                          <i class="fa fa-ellipsis-v"></i></div
                      ></el-col>
                    </el-row>
                  </el-col>
                  <el-col span="3">
                    <i class="fa fa-clock-o"></i>
                  </el-col>
                  <el-col span="3">
                    <div
                      style="
                        background-color: #ff8200;
                        padding: 4px;
                        text-align: center;
                        color: white;
                        border-radius: 30px;
                        font-size: 15px;
                      "
                    >
                      发送
                    </div>
                  </el-col>
                </el-row>
              </el-card>
              <!-- 已登录博客导航栏 -->
              <el-card style="margin-bottom: 5px; height: 40px">
                <el-row style="transform: translateY(-50%)">
                  <el-col span="20">
                    <el-row>
                      <el-col span="3"
                        ><div style="color: #333">全部</div></el-col
                      >
                      <el-col span="3"
                        ><div style="color: #333">原创</div></el-col
                      >
                      <el-col span="3"
                        ><div style="color: #333">视频</div></el-col
                      >
                      <el-col span="4"
                        ><div style="color: #333">V+微博</div></el-col
                      >
                      <el-col span="3"
                        ><div style="color: #333">群微博</div></el-col
                      >
                      <el-col span="2"
                        ><div style="color: #333">&nbsp;</div></el-col
                      >
                      <el-col span="3"
                        ><div style="color: #333">&nbsp;</div></el-col
                      >
                      <el-col span="3"
                        ><div style="color: #333">&nbsp;</div></el-col
                      >
                    </el-row>
                  </el-col>
                  <el-col span="4">
                    <div
                      style="
                        background-color: #f1f2f5;
                        padding: 5px;
                        font-size: 12px;
                        border-radius: 20px;
                        color: #838383;
                      "
                    >
                      <i class="el-icon-search"></i>
                      高级搜索
                    </div>
                  </el-col>
                </el-row>
              </el-card>

              <!-- 博客卡片部分 -->
              <el-card v-for="b in blogArr" style="margin-bottom: 5px">
                <el-row>
                  <el-col span="3">
                    <img
                      :src="getRandomImageUrl(b.userImg)"
                      alt="User"
                      style="width: 50px; border-radius: 100px"
                    />
                  </el-col>
                  <el-col span="18">
                    <span
                      style="
                        font-weight: bolder;
                        vertical-align: top;
                        display: block;
                      "
                      >{{b.username}}</span
                    >
                    <span
                      style="color: #919191; font-size: 12px; display: block"
                    >
                      {{b.createTime}} {{b.follower}}关注了ta</span
                    ></el-col
                  >
                  <el-col span="3">
                    <div
                      style="
                        border-radius: 100px;
                        color: #ff8200;
                        border: 1px solid #ff8200;
                        padding: 5px 10px;
                        text-align: center;
                      "
                    >
                      +关注
                    </div>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col span="3" style="height: 100%">&nbsp;</el-col>
                  <el-col span="21">{{b.content}}</el-col>
                </el-row>
                <el-row>
                  <el-col span="3" style="height: 100%">&nbsp;</el-col>
                  <el-col span="21">
                    <img
                      :src="getRandomImageUrl(b.contentImg)"
                      alt="图片加载失败"
                      style="border-radius: 10px; margin-top: 10px"
                    />
                  </el-col>
                </el-row>
              </el-card>
            </el-col>
            <el-col span="6" style="position: sticky; top: -100px">
              <div
                style="
                  background: linear-gradient(to bottom, #ffcc96, #ffffff);
                  height: 184px;
                  display: flex;
                  flex-direction: column;
                  justify-content: center;
                  align-items: center;
                  border-radius: 3px;
                "
              >
                <img src="./img/text.png" alt="text" />
                <div
                  style="
                    background-color: #ff8200;
                    border-radius: 30px;
                    color: white;
                    width: 50%;
                    padding: 8px;
                    font-size: 15px;
                    text-align: center;
                  "
                >
                  立即登录
                </div>
                <p style="font-size: 14px; color: #919191">
                  还没有微博？<span style="color: #ff8200">立即注册！</span>
                </p>
              </div>
              <!-- 微博热搜部分 -->
              <el-card style="margin-top: 10px">
                <el-row style="font-size: 16px">
                  <span>微博热搜</span>
                  <span style="float: right; color: #919191" @click="refrash"
                    ><i class="fa fa-refresh"></i>点击刷新</span
                  >
                </el-row>
                <el-row style="margin-top: 10px" v-for="h in hotNewsArr">
                  <span>{{h.title}}</span>
                  <span
                    style="
                      font-size: 13px;
                      background-color: #ff8200;
                      padding: 2px;
                      color: white;
                      border-radius: 3px;
                      float: right;
                    "
                    >热</span
                  >
                </el-row>
                <div
                  style="
                    background-color: #f9f9f9;
                    text-align: center;
                    color: #838383;
                    margin-top: 20px;
                    border-radius: 3px;
                    padding: 10px 0 10px 0;
                  "
                >
                  <span class="fullhot"
                    >查看完整热搜榜单&nbsp;&nbsp;<i
                      class="fa fa-angle-right"
                    ></i
                  ></span>
                </div>
              </el-card>
              <div style="margin-top: 50px; font-size: 11px; color: #606060">
                <el-row>
                  <el-col span="2"><i class="el-icon-service"></i></el-col>
                  <el-col span="22">帮助中心</el-col>
                </el-row>
                <el-row>
                  <el-col span="2">&nbsp;</el-col>
                  <el-col span="22">
                    <el-row style="font-size: 10px; text-align: right">
                      <el-col :span="12" style="text-align: left"
                        >微博客服 4000-960-960</el-col
                      >
                      <el-col :span="6">自助服务中心</el-col>
                      <el-col :span="6">常见问题</el-col>
                    </el-row>
                  </el-col>
                </el-row>
              </div>
              <div style="margin-top: 15px; font-size: 11px; color: #606060">
                <el-row>
                  <el-col span="2"><i class="el-icon-service"></i></el-col>
                  <el-col span="22">帮助中心</el-col>
                </el-row>
                <el-row>
                  <el-col span="2">&nbsp;</el-col>
                  <el-col span="22">
                    <el-row style="font-size: 10px; text-align: right">
                      <el-col :span="12" style="text-align: left"
                        >微博客服 4000-960-960</el-col
                      >
                      <el-col :span="6">自助服务中心</el-col>
                      <el-col :span="6">常见问题</el-col>
                    </el-row>
                  </el-col>
                </el-row>
              </div>
              <div style="margin-top: 15px; font-size: 11px; color: #606060">
                <el-row>
                  <el-col span="2"><i class="el-icon-service"></i></el-col>
                  <el-col span="22">帮助中心</el-col>
                </el-row>
                <el-row>
                  <el-col span="2">&nbsp;</el-col>
                  <el-col span="22">
                    <el-row style="font-size: 10px; text-align: right">
                      <el-col :span="12" style="text-align: left"
                        >微博客服 4000-960-960</el-col
                      >
                      <el-col :span="6">自助服务中心</el-col>
                      <el-col :span="6">常见问题</el-col>
                    </el-row>
                  </el-col>
                </el-row>
              </div>
              <div style="margin-top: 15px; font-size: 11px; color: #606060">
                <el-row>
                  <el-col span="2"><i class="el-icon-service"></i></el-col>
                  <el-col span="22">帮助中心</el-col>
                </el-row>
                <el-row>
                  <el-col span="2">&nbsp;</el-col>
                  <el-col span="22">
                    <el-row style="font-size: 10px; text-align: right">
                      <el-col :span="12" style="text-align: left"
                        >微博客服 4000-960-960</el-col
                      >
                      <el-col :span="6">自助服务中心</el-col>
                      <el-col :span="6">常见问题</el-col>
                    </el-row>
                  </el-col>
                </el-row>
              </div>
              <p style="font-size: 11px; color: #606060; text-align: center">
                <i class="fa fa-weibo"></i>&nbsp;Copy right &copy;
                MarkC1D&nbsp;仿写页面
              </p>
            </el-col>
            <el-dialog
              title="写博客"
              :visible.sync="writeblogVisible"
              width="30%"
              :before-close="handleClose"
            >
              <el-form>
                <el-form-item label="微博内容">
                  <el-input
                    placeholder="请输入微博正文"
                    v-model="blog.content"
                  ></el-input>
                </el-form-item>
                <el-form-item label="博客配图">
                  <el-input
                    placeholder="请输入微博配图外链（仅支持外链）"
                    v-model="blog.contentImg"
                  ></el-input>
                </el-form-item>
              </el-form>
              <span slot="footer" class="dialog-footer">
                <el-button @click="writeblogVisible = false">取 消</el-button>
                <el-button type="primary" @click="addBlog">确 定</el-button>
              </span>
            </el-dialog>
          </el-row>
        </el-main>
      </el-container>
    </div>
  </body>
  <script src="./js/vue.min.js"></script>
  <script src="./js/vue-composition-api.prod.js"></script>
  <script src="./js/axios.min.js"></script>
  <script src="./js/Element-ui.min.js"></script>
  <script src="./js/tdesign.min.js"></script>
  <script>
    let v = new Vue({
      el: "#app",
      data: function () {
        return {
          input: "",
          top: 70,
          top2: 70,
          top3: 0,
          textarea: "",
          activeIndex: "3",
          HeaderVisible: "",
          VideoVisible: "",
          Visible: false,
          writeblogVisible: false,
          affixOffsetTop: 10000,
          videoSrc: "video/weibo_login.mp4",
          LoginHide: false,
          blogArr: [],
          hotNewsArr: [],
          blog: {
            content: "",
            contentImg: "",
          },
          hideFunctions: [
            function () {
              this.HeaderVisible = true; // 隐藏头部
            },
            function () {
              this.VideoVisible = false; // 隐藏视频部分
            },
          ],
        };
      },
      created() {
        window.addEventListener("scroll", this.handleScroll);
        axios.get("/HotNewsArr").then((response) => {
          this.hotNewsArr = response.data;
        });
        axios.get("/BlogArr").then((response) => {
          this.blogArr = response.data;
        });
      },
      beforeDestroy() {
        window.removeEventListener("scroll", this.handleScroll);
      },
      methods: {
        hideElement(index) {
          this.hideFunctions[index]();
        },
        refrashBlog() {
          v.$message.success("刷新成功");
          this.loadBlog();
        },
        writeBlog() {
          v.writeblogVisible = true;
        },
        addBlog() {
          // 收集用户输入的博客内容和配图 URL
          const blogContent = this.blog.content;
          const blogImageUrl = this.blog.contentImg;

          // 创建一个对象，包含要发送到服务器的博客内容和配图 URL
          const blogData = {
            content: blogContent,
            contentImg: blogImageUrl,
          };

          // 使用 axios 发送 POST 请求到后端服务器的 /AddBlog 端点
          axios.post("/AddBlog", blogData).then((response) => {
            switch (response.data) {
              case 0:
                v.$message.success("博客发布成功");
                v.writeblogVisible = false;
                this.loadBlog();
                break;
              default:
                v.$message.error("博客发布失败");
                break;
            }
          });
        },
        loadHotNews() {
          axios.get("/HotNewsArr").then((response) => {
            this.hotNewsArr = response.data;
          });
        },
        loadBlog() {
          axios.get("/BlogArr").then((response) => {
            this.blogArr = response.data;
          });
        },
        getRandomImageUrl(baseUrl) {
          return `${baseUrl}?${Math.random()}`;
        },
        handleScrollCol() {
          this.affixOffsetTop = window.scrollY > 200 ? 0 : 10000;
        },
        handleSelect(key, keyPath) {
          console.log(key, keyPath);
        },
        handleScroll() {
          this.Visible = window.scrollY > 200;
        },
        handleOpen(key, keyPath) {
          console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
          console.log(key, keyPath);
        },
        refrash() {
          this.loadHotNews();
        },
      },
    });
  </script>
</html>
